package com.dc.dbus.netty;

import com.dc.dbus.session.client.Client;
import com.dc.dbus.session.listener.ClientSideEventListener;
import com.dc.dbus.session.register.ServiceRegister;
import com.dc.dbus.session.register.ZookeeperServiceRegister;
import com.dc.dbus.transport.netty.client.NettyClientSideTransport;

public class NettyClient {

	protected final static ClientSideEventListener clientSideEventListener = new ClientSideEventListener() {
		@Override
		public void exception(String message, Exception e) {
			System.err.println(message);
			e.printStackTrace(System.err);
		}
	};

	public static void main(String[] args) throws Exception {

		NettyClientSideTransport clientSideTansport = new NettyClientSideTransport(4);

		ServiceRegister serviceRegister = ZookeeperServiceRegister.getClientSideReiger("127.0.0.1:2181",
				clientSideTansport.getServiceChangeListener());

		Client client = new Client(serviceRegister, clientSideTansport, clientSideEventListener);

		ITestService clientStub = client.createClientStub(ITestService.class.getName(), ITestService.class);

		try {
			System.out.println( clientStub.test1("ts0", "111111") );
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			System.out.println( clientStub.test1("ts0", "111111") );
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			System.out.println( clientStub.test2("ts0", "111111") );
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			System.out.println( clientStub.test1("ts1", "111111") );
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
